<?PHP


// -------------------------------------------------------------------------------------------------------
function ShowImageDialog () {
        echo "<html id=dlgImage style='width: 432px; height: 194px; '>";
        echo "<head><title>"._IMAGEDLGTITLE."</title>";
        echo "<style> html, body, button, div, input, select, fieldset { font-family: MS Shell Dlg; font-size: 8pt; position: absolute; }; </style>";
        echo "<script>\n";

        echo "function _CloseOnEsc() {\n";
        echo "        if (event.keyCode == 27) { window.close(); return; }\n";
        echo "}\n";

        echo "function _getTextRange(elm) {\n";
        echo "        var r = elm.parentTextEdit.createTextRange();\n";
        echo "        r.moveToElementText(elm);\n";
        echo "        return r;\n";
        echo "}\n";

        echo "window.onerror = HandleError\n";

        echo "function HandleError(message, url, line) {\n";
        echo "        var str = \""._TABLEERRINTRO."\" + \"\\n\\n\"\n";
        echo "        + \""._TABLEERRERRDS."\" + line + \"\\n\" + message;\n";
        echo "        alert(str);\n";
        echo "        window.close();\n";
        echo "        return true;\n";
        echo "}\n";

        echo "function Init() {\n";
        echo "        var elmSelectedImage;\n";
        echo "        var htmlSelectionControl = \"Control\";\n";
        echo "        var globalDoc = window.dialogArguments;\n";
        echo "        var grngMaster = globalDoc.selection.createRange();\n";

        // event handlers
        echo "        document.body.onkeypress = _CloseOnEsc;\n";
        echo "        btnOK.onclick = new Function(\"btnOKClick()\");\n";
        echo "        txtFileName.fImageLoaded = false;\n";
        echo "        txtFileName.intImageWidth = 0;\n";
        echo "        txtFileName.intImageHeight = 0;\n";

        echo "        if (globalDoc.selection.type == htmlSelectionControl) {\n";
        echo "                if (grngMaster.length == 1) {\n";
        echo "                        elmSelectedImage = grngMaster.item(0);\n";
        echo "                        if (elmSelectedImage.tagName == \"IMG\") {\n";
        echo "                                txtFileName.fImageLoaded = true;\n";
        echo "                                if (elmSelectedImage.src) {\n";
                                                        // fix placeholder src values that editor converted to abs paths
        echo "                                        txtFileName.value          = elmSelectedImage.src.replace(/^[^*]*(\*\*\*)/, \"$1\");\n";
        echo "                                        txtFileName.intImageHeight = elmSelectedImage.height;\n";
        echo "                                        txtFileName.intImageWidth  = elmSelectedImage.width;\n";
        echo "                                        txtVertical.value          = elmSelectedImage.vspace;\n";
        echo "                                        txtHorizontal.value        = elmSelectedImage.hspace;\n";
        echo "                                        txtBorder.value            = elmSelectedImage.border;\n";
        echo "                                        txtAltText.value           = elmSelectedImage.alt;\n";
        echo "                                        selAlignment.value         = elmSelectedImage.align;\n";
        echo "                                }\n";
        echo "                        }\n";
        echo "                }\n";
        echo "        }\n";
        echo "        txtFileName.value = txtFileName.value || \"http://\";\n";
        echo "        txtFileName.focus();\n";
        echo "}\n";

        echo "function _isValidNumber(txtBox) {\n";
        echo "        var val = parseInt(txtBox);\n";
        echo "        if (isNaN(val) || val < 0 || val > 999) { return false; }\n";
        echo "        return true;\n";
        echo "}\n";

        echo "function btnOKClick() {\n";
        echo "        var elmImage;\n";
        echo "        var intAlignment;\n";
        echo "        var htmlSelectionControl = \"Control\";\n";
        echo "        var globalDoc = window.dialogArguments;\n";
        echo "        var grngMaster = globalDoc.selection.createRange();\n";
        // error checking
        echo "        if (!txtFileName.value || txtFileName.value == \"http://\") {\n";
        echo "                alert(\""._IMAGEERRNOURL."\");\n";
        echo "                txtFileName.focus();\n";
        echo "                return;\n";
        echo "        }\n";

        echo "        if (txtHorizontal.value && !_isValidNumber(txtHorizontal.value)) {\n";
        echo "                alert(\""._IMAGEERRHORSP."\");\n";
        echo "                txtHorizontal.focus();\n";
        echo "                return;\n";
        echo "        }\n";

        echo "        if (txtBorder.value && !_isValidNumber(txtBorder.value)) {\n";
        echo "                alert(\""._IMAGEERRBRDTH."\");\n";
        echo "                txtBorder.focus();\n";
        echo "                return;\n";
        echo "        }\n";

        echo "        if (txtVertical.value && !_isValidNumber(txtVertical.value)) {\n";
        echo "                alert(\""._IMAGEERRVERSP."\");\n";
        echo "                txtVertical.focus();\n";
        echo "                return;\n";
        echo "        }\n";

        // delete selected content and replace with image
        echo "        if (globalDoc.selection.type == htmlSelectionControl && !txtFileName.fImageLoaded) {\n";
        echo "                grngMaster.execCommand('Delete');\n";
        echo "                grngMaster = globalDoc.selection.createRange();\n";
        echo "        }\n";

        echo "        idstr = \"\\\" id=\\\"556e697175657e537472696e67\";\n";     // new image creation ID
        echo "        if (!txtFileName.fImageLoaded) {\n";
        echo "                grngMaster.execCommand(\"InsertImage\", false, idstr);\n";
        echo "                elmImage = globalDoc.all['556e697175657e537472696e67'];\n";
        echo "                elmImage.removeAttribute(\"id\");\n";
        echo "                elmImage.removeAttribute(\"src\");\n";
        echo "                grngMaster.moveStart(\"character\", -1);\n";
        echo "        } else {\n";
        echo "                elmImage = grngMaster.item(0);\n";
        echo "                if (elmImage.src != txtFileName.value) {\n";
        echo "                        grngMaster.execCommand('Delete');\n";
        echo "                        grngMaster = globalDoc.selection.createRange();\n";
        echo "                        grngMaster.execCommand(\"InsertImage\", false, idstr);\n";
        echo "                        elmImage = globalDoc.all['556e697175657e537472696e67'];\n";
        echo "                        elmImage.removeAttribute(\"id\");\n";
        echo "                        elmImage.removeAttribute(\"src\");\n";
        echo "                        grngMaster.moveStart(\"character\", -1);\n";
        echo "                        txtFileName.fImageLoaded = false;\n";
        echo "                }\n";
        echo "                grngMaster = _getTextRange(elmImage);\n";
        echo "        }\n";

        echo "        if (txtFileName.fImageLoaded) {\n";
        echo "                elmImage.style.width = txtFileName.intImageWidth;\n";
        echo "                elmImage.style.height = txtFileName.intImageHeight;\n";
        echo "        }\n";

        echo "        if (txtFileName.value.length > 2040) {\n";
        echo "                txtFileName.value = txtFileName.value.substring(0,2040);\n";
        echo "        }\n";

        echo "        elmImage.src = txtFileName.value;\n";

        echo "        if (txtHorizontal.value != \"\") { elmImage.hspace = parseInt(txtHorizontal.value); }\n";
        echo "        else                             { elmImage.hspace = 0; }\n";

        echo "        if (txtVertical.value != \"\") { elmImage.vspace = parseInt(txtVertical.value); }\n";
        echo "        else                           { elmImage.vspace = 0; }\n";

        echo "        elmImage.alt = txtAltText.value;\n";
        echo "        if (txtBorder.value != \"\") { elmImage.border = parseInt(txtBorder.value); }\n";
        echo "        else                         { elmImage.border = 0; }\n";

        echo "        elmImage.align = selAlignment.value;\n";
        echo "        grngMaster.collapse(false);\n";
        echo "        grngMaster.select();\n";
        echo "        window.close();\n";
        echo "}\n";

        echo "</script>";
        echo "</head>";
        echo "<body id=bdy onload='Init()' style='background: threedface; color: windowtext;' scroll=no>";
        echo "<div id=divFileName style='left: 0.98em; top: 1.2168em; width: 7.00em; height: 1.2168em; '>"._IMGAGEURL."</div>";
        echo "<input ID=txtFileName type=text style='left: 8.54em; top: 1.0647em; width: 21.5em; height: 2.1294em; ' tabIndex=10 onfocus='select()'>";
        echo "<div id=divAltText  style='left: 0.98em; top: 4.1067em; width: 6.58em; height: 1.2168em; '>"._IMAGETOOLTIP."</div>";
        echo "<input ID=txtAltText  type=text style='left: 8.54em; top: 3.8025em; width: 21.5em; height: 2.1294em; ' tabIndex=15 onfocus='select()'>";
        echo "<fieldset id=fldLayout  style='left:   .9em; top: 7.1em; width: 17.08em; height: 7.6em;'>";
        echo "<legend id=lgdLayout>"._IMAGELAYOUT."</legend></fieldset>";
        echo "<fieldset id=fldSpacing style='left: 18.9em; top: 7.1em; width: 11.00em; height: 7.6em;'>";
        echo "<legend id=lgdSpacing>"._IMAGESPACING."</legend></fieldset>";
        echo "<div id=divAlign    style='left: 1.82em; top: 9.126em; width: 4.76em; height: 1.2168em; '>"._IMAGEALIGN."</div>";
        echo         "<select ID=selAlignment style='left: 10.36em; top: 8.8218em; width: 6.72em; height: 1.2168em; ' tabIndex=20 size=1>";
        echo        "<option id=optNotSet    value=\"\">"._TABLEDLGALIGNNOTSET."</option>";
        echo        "<option id=optLeft      value=\"left\">"._TABLEDLGALIGNLEFT."</option>";
        echo        "<option id=optRight     value=\"right\">"._TABLEDLGALIGNRIGHT."</option>";
        echo        "<option id=optTexttop   value=\"textTop\">"._TABLEDLGALIGNTEXTTOP."</option>";
        echo        "<option id=optAbsMiddle value=\"absMiddle\">"._TABLEDLGALIGNAMIDDLE."</option>";
        echo        "<option id=optBaseline  value=\"baseline\">"._TABLEDLGALIGNBASELINE."</option>";
        echo        "<option id=optAbsBottom value=\"absBottom\">"._TABLEDLGALIGNABOTTOM."</option>";
        echo        "<option id=optBottom    value=\"bottom\">"._TABLEDLGALIGNBOTTOM."</option>";
        echo        "<option id=optMiddle    value=\"middle\">"._TABLEDLGALIGNMIDDLE."</option>";
        echo        "<option id=optTop       value=\"top\">"._TABLEDLGALIGNTOP."</option>";
        echo        "</select>";
        echo "<div id=divHoriz  style='left: 19.88em; top:  9.1260em; width: 4.76em; height: 1.2168em; '>"._IMAGEHORIZON."</div>";
        echo "<input ID=txtHorizontal style='left: 24.92em; top: 8.82180em; width: 4.20em; height: 2.1294em; ime-mode: disabled;' type=text size=3 maxlength=3 value=\"\" tabIndex=25 onfocus='select()'>";
        echo "<div id=divBorder style='left:  1.82em; top: 12.0159em; width: 8.12em; height: 1.2168em; '>"._IMAGEBORDER."</div>";
        echo "<input ID=txtBorder     style='left: 10.36em; top: 11.5596em; width: 6.72em; height: 2.1294em; ime-mode: disabled;' type=text size=3 maxlength=3 value=\"\" tabIndex=21 onfocus='select()'>";
        echo "<div id=divVert   style='left: 19.88em; top: 12.0159em; width: 3.64em; height: 1.2168em; '>"._IMAGEVERTICAL."</div>";
        echo "<input ID=txtVertical   style='left: 24.92em; top: 11.5596em; width: 4.20em; height: 2.1294em; ime-mode: disabled;' type=text size=3 maxlength=3 value=\"\" tabIndex=30 onfocus='select()'>";
        echo "<button ID=btnOK     style='left: 31.36em; top: 1.0647em; width: 7em; height: 2.2em; ' type=submit tabIndex=40>"._BTNENTER."</button>";
        echo "<button ID=btnCancel style='left: 31.36em; top: 3.6504em; width: 7em; height: 2.2em; ' type=reset  tabIndex=45 onClick='window.close();'>"._BTNCANCEL."</button>";
        echo "</body>";
        echo "</html>";
}

?>
